package com.demo.rabbitmq.ack;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * @author sc
 * Created on  2018/9/16
 */
public class Consumer {
    public static void main(String[] args) throws IOException, TimeoutException, InterruptedException {
        ConnectionFactory factory = new ConnectionFactory();
        factory.setPort(5672);
        factory.setHost("localhost");
        factory.setVirtualHost("/");

        Connection connection = factory.newConnection();

        Channel channel = connection.createChannel();

        String exchange = "ack_ex";
        String routingKey = "ack.#";
        String queue_name = "ack_q";

        channel.exchangeDeclare(exchange,"topic",true);
        channel.queueDeclare(queue_name,false,false,false,null);
        channel.queueBind(queue_name,exchange,routingKey);

        channel.basicQos(0,3,false);

        channel.basicConsume(queue_name, false, new MyConsumer(channel));


    }
}
